from enum import Enum

from .base import *


class Gender(Enum):
    MALE = "male"
    FEMALE = "female"


class User(BaseTable):
    id = fields.IntField(pk=True, description="用户ID")
    name = fields.CharField(max_length=255, description="用户名称")
    nickName = fields.CharField(max_length=50, description="昵称")
    gender = fields.CharEnumField(Gender, default=None, description="性别")
    avatar = fields.CharField(max_length=256, null=True, description="头像")
    address = fields.CharField(max_length=256, null=True, description="地址")
    email = fields.CharField(max_length=256, null=True, description="邮箱")
    password = fields.CharField(max_length=50, description="密码")
    enable = fields.BooleanField(default=False, description="是否启用")

    class Meta:
        table = 'users'  # 数据库中的表名称
        table_description = '用户表'


class Role(BaseTable):
    """用户角色"""
    id = fields.IntField(pk=True, description="角色ID")
    name = fields.CharField(max_length=255, description="角色名称")

    class Meta:
        table = 'role'  # 数据库中的表名称
        table_description = '用户角色表'


class Source(BaseTable):
    """权限表"""
    id = fields.IntField(pk=True, description="资源ID")
    name = fields.CharField(max_length=255, description="资源名称")

    class Meta:
        table = 'source'  # 数据库中的表名称
        table_description = '资源表'


class RolePermission(BaseTable):
    """角色权限表"""
    id = fields.IntField(pk=True, description="自增ID")
    role_id = fields.IntField(null=False, description="用户ID")
    source_id = fields.IntField(null=False, description="资源ID")
    permission = fields.IntField(null=False, description="权限")

    class Meta:
        table = 'role_permission'  # 数据库中的表名称
        table_description = '角色权限表'


class UserRole(BaseTable):
    """用户权限表"""
    id = fields.IntField(pk=True, description="自增ID")
    user_id = fields.IntField(null=False, description="用户ID")
    role_id = fields.IntField(null=False, description="角色ID")

    class Meta:
        table = 'user_role'  # 数据库中的表名称
        table_description = '用户角色表'


class UserPermission(BaseTable):
    """用户权限表"""
    user_id = fields.IntField(null=False, description="用户ID")
    source_id = fields.IntField(null=False, description="资源ID")
    permission = fields.IntField(null=False, description="权限")

    class Meta:
        table = 'user_permission'  # 数据库中的表名称
        table_description = '用户权限表'


class UserPermissionLog(BaseTable):
    """用户权限表"""
    user_id = fields.IntField(null=False, description="用户ID")
    source_id = fields.IntField(null=False, description="资源ID")
    permission = fields.IntField(null=False, description="权限")

    class Meta:
        table = 'user_permission_log'  # 数据库中的表名称
        table_description = '用户权限表'
